package client;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class MacheGUI extends JFrame{
    
    private JPanel prepPanel;
    private JButton aButton;
    private JButton bButton;
    private JButton cButton;
    private JButton dButton;
    private JButton eButton;
    private JButton fButton;
    private JButton gButton;
    private JButton hButton;
    private JButton startButton;
    private JPanel backPanel;
    private JPanel gamePanel;
    private JPanel selfPanel;
    private JPanel infoPanel;
    private JPanel selfIconPanel;
    private JButton c1Button;
    private JButton c2Button;
    private JButton c3Button;
    private JButton c4Button;
    private JButton c5Button;
    private JButton selfNameButton;
    private JButton selfStatusButton;
    private JButton selfSideButton;
    private JButton selfJobButton;

    public MacheGUI(String name) {
        
        super("Mache");
        setBounds(20, 20, 820, 620);
        Container cp = this.getContentPane();
        cp.setLayout(null);
        
        aButton = new JButton();
        aButton.setName("aButton");
        aButton.setBackground(new Color(200, 200, 200, 200));
        aButton.setBounds(70, 120, 150, 150);
        aButton.setText(name);
        
        bButton = new JButton();
        bButton.setName("bButton");
        bButton.setBackground(new Color(200, 200, 200, 200));
        bButton.setBounds(240, 120, 150, 150);
        
        cButton = new JButton();
        cButton.setName("cButton");
        cButton.setBackground(new Color(200, 200, 200, 200));
        cButton.setBounds(410, 120, 150, 150);
        
        dButton = new JButton();
        dButton.setName("dButton");
        dButton.setBackground(new Color(200, 200, 200, 200));
        dButton.setBounds(580, 120, 150, 150);
        
        eButton = new JButton();
        eButton.setName("eButton");
        eButton.setBackground(new Color(200, 200, 200, 200));
        eButton.setBounds(70, 350, 150, 150);
        
        fButton = new JButton();
        fButton.setName("fButton");
        fButton.setBackground(new Color(200, 200, 200, 200));
        fButton.setBounds(240, 350, 150, 150);
        
        gButton = new JButton();
        gButton.setName("gButton");
        gButton.setBackground(new Color(200, 200, 200, 200));
        gButton.setBounds(410, 350, 150, 150);
        
        hButton = new JButton();
        hButton.setName("hButton");
        hButton.setBackground(new Color(200, 200, 200, 200));
        hButton.setBounds(580, 350, 150, 150);
        
        startButton = new JButton();
        startButton.setName("startButton");
        startButton.setBounds(390, 300, 20, 20);
        startButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                start();
            }
        });
        
        prepPanel = new JPanel(){
            public void paintComponent(Graphics g) 
            {
                Image img = new ImageIcon("res/image01.jpg").getImage();
                Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
                setPreferredSize(size);
                setMinimumSize(size);
                setMaximumSize(size);
                setSize(size);
                setLayout(null);
                g.drawImage(img, 0, 0, null);
            } 
        };
        prepPanel.setName("prepPanel");
        prepPanel.setLayout(null);
        prepPanel.setBounds(0, 0, 800, 600);
        prepPanel.add(aButton);
        prepPanel.add(bButton);
        prepPanel.add(cButton);
        prepPanel.add(dButton);
        prepPanel.add(eButton);
        prepPanel.add(fButton);
        prepPanel.add(gButton);
        prepPanel.add(hButton);
        prepPanel.add(startButton);
        
        
        
        gamePanel = new JPanel();
        gamePanel.setName("gamePanel");
        gamePanel.setBackground(new Color(100, 100, 100, 0));
        gamePanel.setBounds(0, 0, 600, 400);
        
        //TODO: selfIconPanel
        
        selfNameButton = new JButton();
        selfNameButton.setName("selfNameButton");
        selfNameButton.setBackground(new Color(160, 130, 230, 200));
        selfNameButton.setForeground(new Color(255, 255, 255, 255));
        selfNameButton.setText(name);
        selfNameButton.setBounds(0, 0, 150, 40);
        
        selfStatusButton = new JButton();
        selfStatusButton.setName("selfStatusButton");
        selfStatusButton.setBackground(new Color(160, 200, 100, 200));
        selfStatusButton.setForeground(new Color(255, 255, 255, 255));
        selfStatusButton.setText("Trading");
        selfStatusButton.setBounds(0, 40, 150, 70);
        
        selfSideButton = new JButton();
        selfSideButton.setName("selfSideButton");
        selfSideButton.setBackground(new Color(100, 150, 200, 200));
        selfSideButton.setForeground(new Color(255, 255, 255, 255));
        selfSideButton.setText("Key");
        selfSideButton.setBounds(0, 110, 75, 40);
        
        selfJobButton = new JButton();
        selfJobButton.setName("selfJobButton");
        selfJobButton.setBackground(new Color(220, 190, 100, 200));
        selfJobButton.setForeground(new Color(255, 255, 255, 255));
        selfJobButton.setText("Doctor");
        selfJobButton.setBounds(75,110, 75, 40);
        
        
        selfIconPanel = new JPanel();
        selfIconPanel.setName("selfIconPanel");
        selfIconPanel.setLayout(null);
        selfIconPanel.setBackground(new Color(200, 200, 200, 200));
        selfIconPanel.setBounds(25, 25, 150, 150);
        selfIconPanel.add(selfNameButton);
        selfIconPanel.add(selfStatusButton);
        selfIconPanel.add(selfSideButton);
        selfIconPanel.add(selfJobButton);
        
        c1Button = new JButton();
        c1Button.setName("c1Button");
        c1Button.setBackground(new Color(200, 200, 200, 200));
        c1Button.setBounds(200, 50, 55, 100);
        
        c2Button = new JButton();
        c2Button.setName("c2Button");
        c2Button.setBackground(new Color(200, 200, 200, 200));
        c2Button.setBounds(280, 50, 55, 100);
        
        c3Button = new JButton();
        c3Button.setName("c3Button");
        c3Button.setBackground(new Color(200, 200, 200, 200));
        c3Button.setBounds(360, 50, 55, 100);
        
        c4Button = new JButton();
        c4Button.setName("c4Button");
        c4Button.setBackground(new Color(200, 200, 200, 200));
        c4Button.setBounds(440, 50, 55, 100);
        
        c5Button = new JButton();
        c5Button.setName("c5Button");
        c5Button.setBackground(new Color(200, 200, 200, 200));
        c5Button.setBounds(520, 50, 55, 100);
        
        selfPanel = new JPanel();
        selfPanel.setName("selfPanel");
        selfPanel.setLayout(null);
        selfPanel.setBackground(new Color(100, 100, 100, 200));
        selfPanel.setBounds(0, 400, 600, 200);
        selfPanel.add(selfIconPanel);
        selfPanel.add(c1Button);
        selfPanel.add(c2Button);
        selfPanel.add(c3Button);
        selfPanel.add(c4Button);
        selfPanel.add(c5Button);
        
        infoPanel = new JPanel();
        infoPanel.setName("infoPanel");
        infoPanel.setBackground(new Color(50, 50, 50, 200));
        infoPanel.setBounds(600, 0, 200, 600);
        
        backPanel = new JPanel(){
            public void paintComponent(Graphics g) 
            {
                Image img = new ImageIcon("res/image01.jpg").getImage();
                Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
                setPreferredSize(size);
                setMinimumSize(size);
                setMaximumSize(size);
                setSize(size);
                setLayout(null);
                g.drawImage(img, 0, 0, null);
            } 
        };
        backPanel.setName("backPanel");
        backPanel.setLayout(null);
        backPanel.setBounds(0, 0, 800, 600);
        backPanel.add(gamePanel);
        backPanel.add(selfPanel);
        backPanel.add(infoPanel);
        backPanel.setVisible(false);
        
        
        
        cp.add(backPanel);
        cp.add(prepPanel);

        setVisible(true);
        setSize(800, 620);
    }
    
    private void start() {
        prepPanel.setVisible(false);
        backPanel.setVisible(true);
    }
}
